package sto.orz.json;

import net.sf.json.JSONObject;

public class JSONResponse implements JSONAdapter {
	private final static String				OUT			= "out";
	private java.util.Map<String, Object>	response	= new java.util.HashMap<String, Object>();

	public JSONResponse() {
		this(true);
	}

	public JSONResponse(boolean done) {
		add("done", done);
	}

	public JSONResponse(boolean done, Object out) {
		this(done);
		add(out);
	}

	public JSONResponse(Object out) {
		this(true, out);
	}

	public JSONResponse add(Object value) {
		return add(OUT, value);
	}

	public JSONResponse add(String key, Object value) {
		response.put(key, value);
		return this;
	}

	public String toJson() {
		JSONObject jsonObject = JSONObject.fromMap(response);
		return jsonObject.toString();
	}
}